﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PROFIP.Persistence.DTO;
using System.Xml.Serialization;
using System.IO;

namespace PROFIP.Persistence
{
    class Writer
    {
        public PROFIPDTO profip { get; set; }
        
        private void Serialize<T>(StreamWriter writer, DataTransferObject<T> dto)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            
            //StringWriter stringWriter = new StringWriter();
//            StreamWriter myWriter = new StreamWriter("myFileName.xml");
            xmlSerializer.Serialize(writer, dto);
//            myWriter.Close();
//            stringWriter.ToString();
        }

        public void Write(Stream stream)
        {
            StreamWriter writer = new StreamWriter(stream);

            if (profip != null)
            {
                Serialize(writer, profip);
            }
            writer.Close();
        }
    }
}
